package com.med.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.med.mapper.NoticeMapper;
import com.med.service.INoticeService;
import com.med.vo.NoticeVO;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Project:internet-based-healthcare
 * Package:com.med.service.impl
 *
 * @Description:
 * @Author:其一
 * @CreateTime: 2025-08-18-11-19
 */
@Service
public class NoticeServiceImpl implements INoticeService {
    @Autowired
    private NoticeMapper noticeMapper;

    //查询医生id
    private Integer getCurrentDoctorId() {
        Integer doctorAdminId = Integer.valueOf(SecurityUtils.getLoginUser().getUserid().intValue());
        Integer doctorId = noticeMapper.selectDoctorId(doctorAdminId);
        return doctorId;
    }

    //查询通知列表
    @Override
    public List<NoticeVO> getNoticePage(NoticeVO noticeVO) {
        Integer receiverId = getCurrentDoctorId();
        return noticeMapper.selectNoticeList(noticeVO,receiverId);
    }

    //修改为已读
    @Override
    public Boolean markAsRead(Integer noticeId) {
        return noticeMapper.updateReadStatus(noticeId, getCurrentDoctorId()) > 0;
    }

    //查询未读数量
    @Override
    public Integer getUnreadCount(Integer noticeType) {
        return noticeMapper.selectUnreadCount(getCurrentDoctorId(), noticeType);
    }
}
